# 单行数据
# 汉王的文本行的识别结果从json转为txt
import json
import os.path as osp
from tqdm import tqdm
dir = "E:\internship\date_test\my\crop_imgfby"
fr = open(osp.join(dir, "hw_bo_result.txt"), "r", encoding="utf-8")
fw = open(osp.join(dir, "hw_rec.txt"), "w", encoding="utf-8")
lines = fr.readlines()
no_txt = 0
for line in tqdm(lines):
    lines = ""
    paraphs = ""
    temp = line.split("\t")
    if len(temp) != 2:
        print("format error!!!")
    fn = temp[0]
    fw.write(fn + "\t")
    label = temp[1]
    labeljson = json.loads(label)
    if "Paraph" in labeljson.keys():
        paraphs = labeljson["Paraph"]
    else:
        fw.write("" + "\n")
        no_txt = no_txt + 1
        continue
    for para in paraphs:
        lines = para["line"]
        if len(lines) == 0:
            fw.write("" + "\n")
            no_txt = no_txt + 1
        for line in lines:
            fw.write(line["code"] + "\n")
print(no_txt)

